#include "unp.h"

static int count;

static void recvfrom_int(int sig)
{
    printf("recv %d datagrams\n", count);
    exit(0);
}

void dg_echo(int fd, struct sockaddr *cliaddr, socklen_t clilen)
{
    ssize_t n;
    socklen_t len;
    char buf[MAXLINE];

    signal(SIGINT, recvfrom_int);

    while (1) {
        len = clilen;
        n = Recvfrom(fd, buf, MAXLINE, 0, cliaddr, &len);
        count++;
    }
}
